package com.entrance;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.entrance.backgroundaction.BackgroundService;
import com.landmesure.bluetoothchat.R;

public class WelcomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        //启动后台服务
        Intent intent = new Intent(this, BackgroundService.class);
        startService(intent);

        //开机动画
        MyHandler myHandler = new MyHandler(this);
        myHandler.sendEmptyMessageDelayed(0, 3000);
    }

    private static final class MyHandler extends Handler {
        private Context mContext;
        private MyHandler(Context context) {
            mContext = context;
        }
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    Intent intent = new Intent(mContext, LoginActivity.class);
                    mContext.startActivity(intent);
                    ((WelcomeActivity) mContext).finish();
                    break;
                default:
                    break;
            }
        }
    }
}
